const defaultData ={
    routes :[
        {
            path:"/Home",
            title:"首页"
        },
        {
            title:"商店",
            children:[
                {
                    path:"/shop",
                    title:"购物"
                },
                {
                    path:"/bian",
                    title:"便利蜂"
                },
                {
                    path:"/luosen",
                    title:"罗森"
                }
            ]
        },
        {
            title:"管理",
            children:[
                {
                    path:"/table",
                    title:"表格"
                },
                {
                    path:"/guan",
                    title:"管理",
                }
            ]
        },

    ],
    list:[]
}


export const reducerName = (state = defaultData, action) => {
    let newState = JSON.parse(JSON.stringify(state))
    switch (action.type) {
        case 'ALLDATA':
            newState.list=action.payload
            return newState
        case 'DELITEM':
            
            newState.list.splice(action.payload.key,1)
            
            return newState
        
        case 'EDITITEM':
            newState.list.forEach(item=>{
                if (item.key === action.payload.item.key) {
                    item.name= action.payload.values.name
                    item.age= action.payload.values.age
                    item.address= action.payload.values.address
                }
            })
            
            return newState

        default:
            return newState
    }
}